//
//  HFCustomLayout.m
//  ThridPackage
//
//  Created by 韩艳锋 on 2019/7/19.
//  Copyright © 2019 韩艳锋. All rights reserved.
//

#import "HFCustomLayout.h"
#import "NSArray+hf.h"
#import "CMDefine.h"

@interface HFCustomLayout()
@property (strong, nonatomic) NSArray<HFLayoutDelegate>*attArray;

@end

@implementation HFCustomLayout

- (void)loadWith:(NSArray<HFLayoutDelegate>*)array {
    self.attArray = array;
}


- (nullable NSArray<__kindof UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect {
    
    return [self.attArray map:^id _Nonnull(id <HFLayoutDelegate>item) {
        return item.attributes;
    }];
}

- (CGSize)collectionViewContentSize {
    id <HFLayoutDelegate> obj = self.attArray.lastObject;
    if (obj && obj.attributes != nil) {
        return CGSizeMake(SCREEN_WIDTH, CGRectGetMaxY(obj.attributes.frame));
    } else {
        return CGSizeZero;
    }
}

@end
